﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyX.Common
{
    //一段范例，指示如何用第三方JSON库来转换消息实体
    //public class JsonHelper
    //{
    //    public static string To(object value)
    //    {
    //        var serializer = Create();
    //        var writer = new System.IO.StringWriter();
    //        var jsonWriter = new JsonTextWriter(writer);

    //        serializer.Serialize(jsonWriter, value);

    //        var result = writer.ToString();

    //        jsonWriter.Close();
    //        writer.Close();

    //        return result;
    //    }

    //    public static object From(string value)
    //    {
    //        var serializer = Create();
    //        var reader = new System.IO.StringReader(value);
    //        var jsonReader = new JsonTextReader(reader);

    //        var result = serializer.Deserialize(jsonReader);

    //        jsonReader.Close();
    //        reader.Close();

    //        return result;
    //    }

    //    private static JsonSerializer Create()
    //    {
    //        var serializer = JsonSerializer.Create(
    //                new JsonSerializerSettings
    //                {
    //                    TypeNameHandling = TypeNameHandling.All
    //                    ,
    //                    TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
    //                });
    //        return serializer;
    //    }
    //}
}
